import thread
import time, random

def worker():
    for i in range(50):
        # pretend we're doing something that takes 10-100 ms
        time.sleep(random.randint(10, 100) / 1000.0)
        print thread.get_ident(), "-- task", i, "finished"

#
# try it out!

for i in range(2):
    thread.start_new_thread(worker, ())

time.sleep(1)

print "goodbye!"

## 311 -- task 0 finished
## 265 -- task 0 finished
## 265 -- task 1 finished
## 311 -- task 1 finished
## ...
## 265 -- task 17 finished
## 311 -- task 13 finished
## 265 -- task 18 finished
## goodbye!
